The Sound Input Manager provides two functions, SetupSndHeader and SetupAIFFHeader , to help you set up headers for sound resources and sound files.
You can use the SetupSndHeader function to construct a sound resource containing sampled sound that can be passed to the SndPlay function.
FUNCTION SetupSndHeader (sndHandle: Handle;
numChannels: Integer;
sampleRate: Fixed;
sampleSize: Integer;
compressionType: OSType;
baseFrequency: Integer;
numBytes: LongInt;
VAR headerLen: Integer): OSErr;
The SetupSndHeader function creates a format 1 'snd ' resource for a sampled sound. The resource contains a sound resource header that links the sound to the sampled synthesizer, a single sound command (a bufferCmd command to play the accompanying data), and a sampled sound header. You can use SetupSndHeader to construct a sampled sound header that can be passed to the Sound Manager's SndPlay function or stored as an 'snd ' resource. After calling the SetupSndHeader function, your application should place the sampled-sound data directly after the sampled sound header so that, in essence, the sampled sound header's final field contains the sound data.
The sampled sound is in one of three formats depending on several of the parameters passed. Table 3 shows how SetupSndHeader determines what kind of sound header to create.
'NONE'
|
SoundHeader
|
||
'NONE'
|
ExtSoundHeader
|
||
'NONE'
|
ExtSoundHeader
|
||
CmpSoundHeader
|
A good way to use this function is to create a handle in which you want to store a sampled sound, then call SetupSndHeader with the numBytes parameter set to 0 to see how much room the header for that sound will occupy and hence where to append the audio data. Then record the data into the handle and call SetupSndHeader again with numBytes set to the correct amount of sound data recorded. The handle filled out in this way can be passed to SndPlay to play the sound.
The trap macro and routine selector for the SetupSndHeader function are
For an example that uses the SetupSndHeader function to set up a sound header before recording, see Listing 42 .
You can use the SetupAIFFHeader function to set up a file that can subsequently be played by SndStartFilePlay .
FUNCTION SetupAIFFHeader (fRefNum: Integer;
numChannels: Integer;
sampleRate: Fixed;
sampleSize: Integer;
compressionType: OSType;
numBytes: LongInt;
numFrames: LongInt): OSErr;
The SetupAIFFHeader function creates an AIFF or AIFF-C file header, depending on the parameters passed to it:
The SetupAIFFHeader function might format a sound file as an AIFF file even if the File Manager file type of a file is 'AIFC' . The Sound Manager will still play such files correctly.
The AIFF header information is written starting at the current file position of the file specified by the fRefNum parameter, and the file position is left at the end of the header upon completion. The SetupAIFFHeader function creates a Form Chunk, a Format Version Chunk, a Common Chunk, and a Sound Data chunk, but it does not put any sound data at the end of the Sound Data Chunk.
A good way to use this routine is to create a file that you want to store a sound in, then call SetupAIFFHeader with numBytes set to 0 to position the file to be ready to write the audio data. Then record the data to the file, set the file position to the beginning of the file, and call SetupAIFFHeader again with numBytes set to the correct amount of sound data recorded. The file created in this way can be passed to the SndStartFilePlay function to play the sound.
If recording produces an odd number of bytes of sound data, you must add a pad byte to make the total number of bytes even.
Because the SetupAIFFHeader function moves memory, you should not call it at interrupt time.
| Previous | Chapter contents | Chapter top | Section top | Next |